home *** CD-ROM | disk | FTP | other *** search
- Path: EU.net!sun4nl!xs4all!falstaff
- From: falstaff@xs4all.nl (Falstaff)
- Newsgroups: comp.os.linux.help,comp.lang.c
- Subject: Re: strncpy bug?
- Date: 14 Mar 1996 09:46:42 GMT
- Organization: XS4ALL, networking for the masses
- Message-ID: <4i8pu2$lq7@news.xs4all.nl>
- References: <ccurtis.826776589@ee.fit.edu>
- NNTP-Posting-Host: xs1.xs4all.nl
- X-Newsreader: NN version 6.5.0 #666 (NOV)
-
- ccurtis@ee.fit.edu (Christopher W. Curtis) writes:
-
- >Hi.
-
- >I was wondering if this is a Linux thing (kernel 1.2.1) or a
- >more general 'problem'. If you call strncpy as such:
- > strncpy( dest, NULL, x );
- >it will seg fault. Is this common among all platforms, or
- >just with Linux?
-
- >The man page says nothing about it, but I would have presumed
- >that if str[n]cpy were passed NULL as a source, it would
- >merely catenate the destination. Did I presume wrong?
-
- If the strncpy() manual does not report any special cases, you should
- assume that there are none.
- For example, free() supports NULL as a special no-op case, but
- strncpy() just tries to copy a string from address 0.
- As this is generally not correct, Linux will trap accesses to address
- 0, so you can immediately see your program has an error.
-
- Frank
- --
- The famous GIICM now on line: http://www.xs4all.nl/~falstaff/GIICM.html
- ------------------------------------------------------------------------
- Frank A. Vorstenbosch +31-(70)-355 5241 falstaff@xs4all.nl
-